import http from "@/utils/http.js"//引入http模块
const module = {
    namespaced:true,//开启命名空间
    state: {
        dataList: [], //保存后端数据状态
        filmTotal: 0,
    },
    mutations: {
        setFilmData(store,filmData) {
            store.dataList = [...store.dataList,...filmData]
            // console.log("setFilm中", filmData);
        },
        setTotal(store,total) {
            store.filmTotal = total;
        },
        clearFilmData(store) {
            store.dataList = [];
            store.filmTotal = 0;
        }
    },
    actions: {
        getFilmData(store, options) {
            return http({
                url:`/gateway?cityId=${options.cityId}&pageNum=${options.current}&pageSize=10&type=1&k=5098835`,
                headers:{
                    'X-Host': 'mall.film-ticket.film.list'
                }
            }).then((res) => {
                //console.log("dispatch中的请求",res.data.data.films);
                // this.dataList = res.data.data.films
                // // 保存总条数
                // this.total = res.data.data.total
              
                // console.log(res);
                
                store.commit("setFilmData",res.data.data.films)
                store.commit("setTotal",res.data.data.total)
            })
        }
    }
}
export default module